// pages/wallet/wallet.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    istrue:{
      type:Boolean,
      cz:false,
    },
      money:0,
      list:[],
      page:1, //当前页
      size:5, //显示数据量
      token:null,
      userInfo:null,
      CorpAccount:null,
      moneylist:[],
      array: ['消费', '充值'],
      objectArray: [
        {
          id: 0,
          name: '消费'
        },
        {
          id: 1,
          name: '充值'
        }
      ],
      index: 0,
      date: '2021-07-02',
      time: '12:01',
      walletswitchleft:true,
      walletswitchright:false,
      alits:[],
      amoney:null,
      amoneyindex:0,
  },

    /***选择器*/
    bindPickerChange: function (e) {
      console.log('picker发送选择改变，携带值为', e.detail.value)
      let that = this
      let token = wx.getStorageSync('token')
      wx.request({
        url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
        data: {
          token: token,
          cmd: 'GetAccountRunning',
          InOut:e.detail.value,
          DateFrom:new Date().toISOString().substring(0, 10),
          DateTo:new Date().toISOString().substring(0, 10),
          IsCorp:0,
          PageNo:'1',
          PageSize:'20'
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (data) {
            let moneylist= data.data.DATA.Running;
            that.setData({
              moneylist: moneylist,
              alist:moneylist
            })
         
        }
      })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    let  userInfo =  wx.getStorageSync('userInfo');
    let  token =  wx.getStorageSync('token');
    let moneylist = that.data.moneylist;
    //获取用户余额
    wx.request({
      url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
      data: {
        token: token,
        cmd: 'GetAccount',
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (data) {
          console.log(data.data.STATUS)
          if(data.data.STATUS=='Success'){
            that.setData({
              money: data.data.DATA.Account,
              CorpAccount: data.data.DATA.CorpAccount,
              amoney:data.data.DATA.Account,
            })
          }else{
            wx.showToast({
              title:data.data.DESC,
              icon: 'error',
              duration: 2000
            })
          }
      }
    })
    //获得充值金额 列表
    wx.request({
      url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
      data: {
        token: token,
        cmd: 'getChargeMoneys',
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (data) {
          console.log(data.data)
          if(data.data.STATUS=='Success'){
            that.setData({
              list: data.data.DATA.List,
              alist:data.data.DATA.List,
            })
          }else{
            wx.showToast({
              title:data.data.DESC,
              icon: 'error',
              duration: 2000
            })
          }
          
      }
    })
    //获得用户流水
    wx.request({
      url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
      data: {
        token: token,
        cmd: 'GetAccountRunning',
        InOut:0,
        DateFrom:new Date().toISOString().substring(0, 10),
        DateTo:new Date().toISOString().substring(0, 10),
        IsCorp:0,
        PageNo:'1',
        PageSize:'20'
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (data) {
          let moneylist= data.data.DATA.Running;
          console.log(moneylist);
          that.setData({
            moneylist: moneylist,
            alist:moneylist
          })
          console.log(moneylist)
      }
    })
    //获取用户消费记录
    that.setData({
      userInfo: userInfo,
      token: token
    })
  },
  /**切换钱包**/
  onpersonal(e){
    let that = this;
    let walletswitchleft=that.data.walletswitchleft;
    let walletswitchright=that.data.walletswitchright;
    that.setData({
      walletswitchleft:true,
      walletswitchright:false,
      money:that.data.amoney,
      moneylist:that.data.alist,
      amoneyindex:0
    })
  },
  onenterprise(e){
    let that = this;
    let walletswitchleft=that.data.walletswitchleft;
    let walletswitchright=that.data.walletswitchright;
    that.setData({
      walletswitchleft:false,
      walletswitchright:true,
      money:that.data.CorpAccount,
      moneylist:[],
      amoneyindex:1
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  onmoneytopup(e){
    let _this = this
    _this.setData({
      cz:true
    })
    console.log(1);
  },
  ononeself(e){
    let _this = this
    _this.setData({
      zdy:true
    })
    console.log(2);
  },
  navigateBack() {
    wx.navigateBack({
      delta: 2
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
})